package easyjs

import "gitee.com/haodreams/libs/eurl"

type Eurl struct {
}

func (m *Eurl) GetWithHeaders(url string, headers map[string]string) (any, error) {
	var opts []eurl.Option
	for k, v := range headers {
		opts = append(opts, eurl.WithHeader(k, v))
	}
	data, code, err := eurl.GET(url, opts...)
	if err != nil {
		return nil, err
	}
	return map[string]any{"data": string(data), "code": code}, err
}

func (m *Eurl) GET(url string) (any, error) {
	data, code, err := eurl.GET(url)
	if err != nil {
		return nil, err
	}
	return map[string]any{"data": string(data), "code": code}, err
}

func (m *Eurl) POST(url string, jsdata string) (any, error) {
	data, code, err := eurl.POST(url, eurl.WithBody([]byte(jsdata)))
	if err != nil {
		return nil, err
	}
	return map[string]any{"data": string(data), "code": code}, err
}

func (m *Eurl) JSON(url string, jsdata string) (any, error) {
	data, code, err := eurl.JSON(url, jsdata)
	if err != nil {
		return nil, err
	}
	return map[string]any{"data": string(data), "code": code}, err
}
